#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <math.h>
struct s {
	char name[9];
	int y;
	int m;
	int e;
}stu[1000];
int main()
{
	int n;
	scanf("%d", &n);
	int sum[1000];
	int yme[450] = { 0 };
	for (int i = 0; i < n; i++)
	{
		scanf("%s %d %d %d", stu[i].name, &stu[i].y, &stu[i].m, &stu[i].e);
		getchar();
		sum[i] = stu[i].y + stu[i].m + stu[i].e;
	}
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			if (abs(sum[i] - sum[j]) <= 10)
			{
				if (abs(stu[i].y - stu[j].y) <= 5)
					if (abs(stu[i].m - stu[j].m) <= 5)
						if (abs(stu[i].e - stu[j].e) <= 5)
							printf("%s %s\n", stu[i].name, stu[j].name);
			}
		}
	}
	return 0;
}